﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SmartCA.Infrastructure.DomainBase;

namespace SmartCA.Infrastructure.RepositoryFramework
{
    /// <summary>
    /// 定义一个泛型的仓储接口，包括：
    /// 1. 根据key（实体键）获取实体
    /// 2. 新增对象
    /// 3. 索引
    /// 4. 移除对象
    /// </summary>
    /// <typeparam name="T"></typeparam>

    public interface IRepository<T> where T:EntityBase
    {
        //void SetUnitOfWork(IUnitOfWork unitOfWork);

        /// <summary>
        /// 根据key（实体键）获取实体
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        T FindBy(object key);

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="item"></param>
        void Add(T item);

        /// <summary>
        /// 索引器
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        T this[object key] { get; set; }
        
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="item"></param>
        void Remove(T item);
    }
}
